package com.guigu.guliproduct.controller;


import com.guigu.gulicommon.constant.enumes.res.CommonResCode;
import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.guliproduct.entity.Category;
import com.guigu.guliproduct.entity.dto.AddCategoryDto;
import com.guigu.guliproduct.entity.vo.GetCateGoryTreeVo;
import com.guigu.guliproduct.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品三级分类 前端控制器
 *
 * @author 陈俊杰
 * @since 2024-07-13
 */
@Validated
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 所有一级分类和其子分类
     *
     * @return 所有一级分类和其子分类
     */
    @GetMapping("/getAllCategory")
    public Res<GetCateGoryTreeVo> findAllCategory() {
        return categoryService.getAllCategory();
    }

    /**
     * 新增分类
     *
     * @param category 分类
     * @return Category
     */
    @PostMapping("/addCategory")
    public Res<Category> addCategory(@Validated @RequestBody AddCategoryDto category) {
        Category proGetCategoryTreeVo = categoryService.addCategory(category);
        return new Res<>(CommonResCode.SUCCESS, proGetCategoryTreeVo);
    }


}
